# -*- coding:utf-8 -*-
from django.template.loader import get_template
from django.template import Template, Context
from django.http import HttpResponse
import codecs

def index(request):
    t=get_template('index.htm')
    html=t.render(Context({}))
    return HttpResponse(html)

def article_index(request):
    t=get_template('article_index.htm')
    html=t.render(Context({}))
    return HttpResponse(html)

def article(request,filenum):
    t=get_template('content.htm')
    jp_txt=codecs.open('./media/jp_txt/'+filenum+'.GSBc.txt','rb','utf16').readlines()
    cn_txt=codecs.open('./media/cn_txt/'+filenum+'.GSBc.txt','rb','utf16').readlines()

    article_title_dict={}
    articlelist=codecs.open('./media/articlelist.txt','rb','utf16').readlines()
    for title in articlelist:
        article_title_dict[title[:3]]=title[9:-2]
    if filenum in article_title_dict:
        article_title=article_title_dict[filenum]
    else:
        article_title='99滴眼泪小说集'
    html=t.render(Context({'jptxt': jp_txt,'cntxt':cn_txt,'article_title':article_title}))
    return HttpResponse(html)
